/**
 * 只为了读入读出
 */
package org.whuims.pois.dao;

import org.whuims.pois.action.result.ClusterVo;
import org.whuims.pois.action.result.DataVo;
import org.whuims.pois.hibernate.BaseDao;

import java.util.ArrayList;
import java.util.List;

/**
 * @author hysk34
 *         <p/>
 *         2010-10-30
 */
public class MainPageDao {

    BaseDao baseDao = new BaseDao();
    StarDao starDao = new StarDao();

    /**
     * 构造查询最新指定类型数据的sql语句
     * 代码同NewsDao中的getNewest，只是得到个数不用
     */
    public List<DataVo> getNewest(String type, long topicid, String userName) {
        List<org.whuims.pois.action.result.DataVo> list = baseDao.queryByParamArr(1, 5, "select new org.whuims.pois.action.result.DataVo(id,titlecontent,titlelink,abstext,sitename,newstime,crawltime) from DataC where topicid=? and type= ? and status=0 order by newstime desc", topicid, type);
        List<Long> starList = baseDao.findByParamsArr("select dataid from Stare where user=?", userName);
        for (int i = 0; i < list.size(); i++) {
            org.whuims.pois.action.result.DataVo dataVo = list.get(i);
            if (starList.contains(dataVo.getId())) {
                dataVo.setStar(true);
            }
        }
        return list;
    }

    //获得最新的负面新闻
    public List<DataVo> getNegative() {
        //TODO:负面度>5的DataC
        return new ArrayList<DataVo>();
    }

    /**
     * 读取聚类结果
     *
     * @param topicId                      主题ID
     * @param type：类型，today,week,yesterday
     */
    public List<ClusterVo> getClusterList(long topicId, String type) {
        List<ClusterVo> list = baseDao.findByParamsArr(
                "select new org.whuims.pois.action.result.ClusterVo(c.id,c.recordid , d.titlecontent , d.titlelink , d.abstext , c.count, c.value , c.crawltime, c.type,c.category) " +
                        "from Cluster c,DataC d where c.recordid=d.id and c.topicId=? and c.type=?", topicId, type
        );
        return list;
    }

    public List<ClusterVo> getYesterdayList(long topicId) {
        return getClusterList(topicId, "yesterday");
    }

    public List<ClusterVo> getTodayList(long topicId) {
        return getClusterList(topicId, "today");
    }


//    //获取焦点关注
//    public List<F> getFocus() {
//        FocusDao dao = new FocusDao();
//        return dao.select();
//    }


    //获取我的关注
    public List<DataVo> getStarNews(String userName, long topicId) {
        return starDao.list(1, 5, userName, topicId);
    }

}
